enyo.kind({
	name: "com.RexToy.abstractCvtView",
	kind: enyo.Control,
	
	calc: function(curUnit, curVal)
	{
		var baseVal = curVal;
		if(curUnit!=this.baseUnit)
		{
			var expr = this.fomular[curUnit+"->"+this.baseUnit];
			var stmt = "var "+curUnit+"="+curVal+";"+expr;
			this.log("calc base value:["+stmt+"]");
			baseVal = eval(stmt);
		}
		
		this.log("baseVal = "+baseVal);
		
		for(var i=0;i<this.units.length;i++)
		{
			var toCalcUnit = this.units[i];
			if(toCalcUnit != curUnit)
			{
				var expr = this.fomular[this.baseUnit+"->"+toCalcUnit];
				var stmt = "var "+this.baseUnit+"="+baseVal+";"+expr;
				this.log("calc "+toCalcUnit+"["+stmt+"]");
				var toCalcVal = this.roundIt(eval(stmt), 4);
				this.$[toCalcUnit].setValue(toCalcVal);
			}
		}
		
	},
	
	showAlert: function()
	{
		var pop = this.$.Popup;
		if(!pop)
		{
			pop = this.createComponent({kind: "Popup", name: "Popup",
									components: [{content: $L("Please enter a number.")}]});
		}
		pop.openAtCenter();
	},

	isNumber: function(ctrl)
	{
		var v = ctrl.getValue().trim();
		if(v=="" || isNaN(v))
		{			
			this.showAlert();			
			return false;
		}
		return true;
	},
	
	getNumber: function(ctrl)
	{
		return Number(ctrl.getValue());
	},
	
	roundIt: function(val, precise)
	{
		var factor = Math.pow(10, precise);
		return Math.round(val * factor)/factor;
	}
});